package com.mbbmap.map;

import java.io.InputStream;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import com.classes.AutoScript;
import com.classes.CaseOutlet;
import com.classes.Casemast;
import com.classes.CasemastFactory;
import com.classes.CharArrayWriterResponse;
import com.classes.MerchantFactory;
import com.classes.Notification;
import com.classes.OutletFactory;
import com.mbbmap.app.dao.UserDao;
import com.mbbmap.app.home.SecUsersHome;
import com.mbbmap.app.manager.ConfigManager;
import com.mbbmap.security.action.CommonDispatchAction;
import com.mbbmap.security.dao.SecAccessDao;
import com.mbbmap.security.dao.SecUserDao;
import com.mbbmap.util.Constants;
import com.mbbmap.util.EncryptionHelper;
import com.mbbmap.util.StringUtils;

public class SubmitAppAction extends CommonDispatchAction {
	private int iApp0 = 0; //APP000
	private String iMod = "";
	private static final String modApproval = "MOD001";
	private static final String CONFIG_FILE = "/system.properties";
	private static final java.util.Properties appCfg = new java.util.Properties();
	
	private boolean authorized(HttpServletRequest request){
		HttpSession session = request.getSession(false);
		@SuppressWarnings("unchecked")
		ArrayList<SecAccessDao> secGroupAccessList = (ArrayList<SecAccessDao>) session.getAttribute(Constants.LOGON_ACCESS_LIST);
		
		this.iApp0 = 0;
		
		for(int i=0;i<secGroupAccessList.size();i++){
			SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
			String strModuleCode  = secaccessDao.getModuleCode();
			if(strModuleCode.equals("APP000")){
				if(secaccessDao.getWriteFlag().equals("01")){
					this.iApp0 = 1;
				}
				
				if(secaccessDao.getReadFlag().equals("01")){
					this.iApp0 = 2;
				}
				
				if(secaccessDao.getUpdateFlag().equals("01")){
					this.iApp0 = 3;
				}
			}
			
			if(strModuleCode.startsWith("MOD")){
				this.iMod = strModuleCode;
			}
		}
		
		if(this.iApp0 > 0) {
			return true;
		}
		
		return false;
	}
	
	public ActionForward status_action(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.status_action";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		String status_group = StringUtils.decryptJSON(request.getParameter("status_group"));
		String status_action = EncryptionHelper.decrypt(request.getParameter("status_action"));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("note", request.getParameter("status_note"));
		post.put("action", status_action);
		post.put("assign_to", status_group);
		post.put("email", request.getParameter("status_email"));
		
		long hist_id = CasemastFactory.action_submit(case_id, post, oSecUserDao.getLogonId(), 1);
		if(hist_id < 0){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		
		// Trigger notification process
		Casemast c = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
		if(c == null){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		String strEMerchant = (String) session.getAttribute(Constants.MERCHANT_KEY);
		
		Notification n = new Notification();
		n.setUsers(status_group, strEMerchant);
		n.setInfo("note", request.getParameter("status_note"));
		n.setInfo("action", status_action);
		n.setInfo("hist_id", String.valueOf(hist_id));
		n.setCasemast(c);
		
		boolean ok = n.run("dashboard", oSecUserDao.getLogonId());
		if(ok == false){
			json_error(n.getMessage(), response);
			return null;
		}
		
		if(post.get("email").equals("Y")){
			ok = n.run("email", oSecUserDao.getLogonId());
			if(ok == false){
				json_error(n.getMessage(), response);
				return null;
			}
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward status_action2(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.status_action2";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("action", EncryptionHelper.decrypt(request.getParameter("status_action2")));
		
		long hist_id = CasemastFactory.action_submit(case_id, post, oSecUserDao.getLogonId(), 2);
		if(hist_id < 0){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward extremark_action(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.extremark_action";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("external_remark", request.getParameter("external_remark"));
		
		boolean ok = CasemastFactory.extremark_submit(case_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward notification_action(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.notification_action";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		long notification_id = Long.parseLong(request.getParameter("notification_id"));
		
		
		Notification n = new Notification();
		boolean ok = n.updateNotificationStatus(notification_id, "Done", oSecUserDao.getLogonId());
		if(ok == false){
			json_error(n.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward duplicate_case(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.duplicate_case";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		//int merchant_id = Integer.parseInt(request.getParameter("merchant_id"));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
		if(m_case == null){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
			
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("app_type", m_case.getType());
		post.put("ownership_status", m_case.getMerchant().getOwnershipStatus());
		post.put("registered_name", m_case.getMerchant().getRegisteredName());
		post.put("registered_no", m_case.getMerchant().getRegisteredNo());
		post.put("nature_of_business", m_case.getMerchant().getDesc());
		post.put("mcc_code", m_case.getMerchant().getMCCCode());
		post.put("paid_up_capital", m_case.getMerchant().getPaidUpCapital());
		post.put("recall_barcode_no", m_case.getMerchant().getRecallBarcode());
		post.put("gst_registration", m_case.getMerchant().getGst_registration());
		post.put("rmcd_approval_no", m_case.getMerchant().getRmcd_approval_no());
		post.put("years_in_business", m_case.getMerchant().getYearInBusiness());
		post.put("avr_ticket_size", m_case.getMerchant().getAvgTicketSize());
		post.put("current_acquirer", m_case.getAcquirer());
		post.put("bank_name", m_case.getMerchant().getCurrBank());
		post.put("current_acc_no", m_case.getMerchant().getCurrAccNo());
		post.put("avr_monthly_deposit", m_case.getMerchant().getCurrAvgDeposit());
		post.put("monthly_deposit_entries", m_case.getMerchant().getCurrAvgDepositDtl());
		post.put("amex_auth_sign", m_case.getMerchant().getAmexAuthSign());
		post.put("last_ref_no", m_case.getReferenceNo());
		
		MerchantFactory m = new MerchantFactory();
		boolean ok = m.newMerchantCase(post, "put up", oSecUserDao.getLogonId(), oSecUserDao.getGroupCode(), oSecUserDao.getCountryCode());
		if(ok == false){
			json_error(m.getMessage(), response);
			return null;
		}
		
		
		
		if(m.getMerchantID() == 0 || m.getCaseID() == 0) {
			json_error("Failed to add Business Detail.", response);
			return null;
		}
		
		
		post = new TreeMap<String, String>();
		post.put("match_trace", m_case.getMerchant().getMatchTrace());
		
		ok = m.editMerchantCase((int) m.getMerchantID(), (int) m.getCaseID(), post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(m.getMessage(), response);
			return null;
		}
		
		
		OutletFactory o = new OutletFactory();
		ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
		if(c_outlets == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		if(c_outlets.size() > 0){
			CaseOutlet c_outlet = c_outlets.get(0);
			
			post = new TreeMap<String, String>();
			post.put("merchant_id", Long.toString(m.getMerchantID()));
			post.put("case_id", Long.toString(m.getCaseID()));
			post.put("registered_name", c_outlet.getOutlet().getMerchant().getRegisteredName());
			post.put("registered_no", c_outlet.getOutlet().getMerchant().getRegisteredNo());
			post.put("trading_name", c_outlet.getOutlet().getName());
			post.put("contact_person", c_outlet.getOutlet().getCTName());
			post.put("designation", c_outlet.getOutlet().getCTDesignation());
			post.put("email", c_outlet.getOutlet().getCTEmail());
			post.put("telephone_no", c_outlet.getOutlet().getCTTel());
			post.put("fax_no", c_outlet.getOutlet().getCTFax());
			post.put("esa_ref_no", c_outlet.getESARefNo());
			post.put("no_of_terminal", c_outlet.getNumTerminal());
			post.put("terminal_rental_fee", c_outlet.getTrmRental());
			post.put("terminal_owner", c_outlet.getTrmOwner());
			post.put("license_no", c_outlet.getOutlet().getLisenceNo());
			post.put("license_type", c_outlet.getOutlet().getLicenseType());
			post.put("state", c_outlet.getOutlet().getLicenseState());
			post.put("issuer", c_outlet.getOutlet().getLicenseIssuer());
			post.put("expiry_date", c_outlet.getOutlet().getLicenseExpiry());
			post.put("risk_level", c_outlet.getOutlet().getRiskLevel());
			post.put("terminal_deposit_wired", c_outlet.getTrmDepositWired());
			post.put("terminal_deposit_wireless", c_outlet.getTrmDepositWireless());
			post.put("terminal_rental_deposit_wired", c_outlet.getTrmRentalDepositWired());
			post.put("terminal_rental_deposit_wireless", c_outlet.getTrmRentalDepositWireless());
			post.put("advance_terminal_rental", c_outlet.getTrmRentalAdvance());
			post.put("risk_level", c_outlet.getOutlet().getRiskLevel());
			post.put("total_cheque_amt", c_outlet.getChequeAmt());
			
			String bank_issuer_branch = c_outlet.getChequeIssuer();
			post.put("bank_issuer", bank_issuer_branch.substring(0, bank_issuer_branch.lastIndexOf('|')));
			post.put("bank_branch", bank_issuer_branch.substring(bank_issuer_branch.lastIndexOf('|') + 1));
			
			post.put("cheque_no", c_outlet.getChequeNo());
			post.put("cheque_date", c_outlet.getChequeDate());
			post.put("terminal_id", c_outlet.getTerminalID());
			post.put("terminal_id_no", c_outlet.getTerminalIDNo());
			post.put("terminal_install_date", c_outlet.getTerminalInstallDate());
			
			ok = o.newCaseOutlet(post, oSecUserDao.getLogonId());
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
			
			
			if(o.getOutletID() == 0) {
				json_error("Failed to add Outlet Detail.", response);
				return null;
			}
			
			
			
			post = new TreeMap<String, String>();
			post.put("payment_info", c_outlet.getOutlet().getPaymentOpt());
			post.put("statement_opt", c_outlet.getOutlet().getStatementOpt());
			post.put("other_info", c_outlet.getOutlet().getOtherInfo());
			post.put("physical_address", c_outlet.getOutlet().getAddress());
			post.put("payment_address", c_outlet.getOutlet().getAddress2());
			post.put("correspondence_address", c_outlet.getOutlet().getAddress3());
			post.put("mdr", c_outlet.getOutlet().getMDRRate());
			
			ok = o.editCaseOutlet((int) m.getCaseID(), (int) o.getOutletID(), post, oSecUserDao.getLogonId());
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
			
			
		}
		
		
		JSONObject data = new JSONObject();
		data.put("merchant_id", EncryptionHelper.encrypt(m.getMerchantID() + ""));
		data.put("case_id", EncryptionHelper.encrypt(m.getCaseID() + ""));
	
		json_ok(response, data);
		
		return null;
	}
	
	public ActionForward create_business_detail(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

			final String PROG_ID="SubmitAppAction.create_business_detail";

			System.out.println(PROG_ID + " : BEGIN");
			HttpSession session = request.getSession(false);
			
			//String nextPage = null;
			
			//check session condition
			if (session == null){
				//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
				json_error("Session not found.", response);
				return null;
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
				String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
				session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
				if (DEBUG) System.out.println("... Javascript not enable");
				//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
				json_error("Javascript not enabled.", response);
				return null;
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
				if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
					if (DEBUG) System.out.println("sessionstatus !=null 2");
					String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
					session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
					
					json_error("sessionstatus !=null 2", response);
					return null;

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				//return mapping.findForward(strFwd);
				json_error("Your session has expired", response);
				return null;
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(this.authorized(request) == false){
				json_error("Unauthorized access.", response);
				return null;
			}
				
			TreeMap<String, String> post = new TreeMap<String, String>();
			post.put("app_type", request.getParameter("app_type"));
			post.put("ownership_status", request.getParameter("ownership_status"));
			post.put("registered_name", request.getParameter("registered_name"));
			post.put("registered_no", request.getParameter("registered_no"));
			post.put("nature_of_business", request.getParameter("nature_of_business"));
			post.put("mcc_code", request.getParameter("mcc_code"));
			post.put("paid_up_capital", request.getParameter("paid_up_capital"));
			post.put("recall_barcode_no", request.getParameter("recall_barcode_no"));
			post.put("gst_registration", request.getParameter("gst_registration"));
			post.put("rmcd_approval_no", request.getParameter("rmcd_approval_no"));
			post.put("years_in_business", request.getParameter("years_in_business"));
			post.put("avr_ticket_size", request.getParameter("avr_ticket_size"));
			post.put("current_acquirer", request.getParameter("current_acquirer"));
			post.put("bank_name", request.getParameter("bank_name"));
			post.put("current_acc_no", request.getParameter("current_acc_no"));
			post.put("avr_monthly_deposit", request.getParameter("avr_monthly_deposit"));
			post.put("monthly_deposit_entries", request.getParameter("monthly_deposit"));
			post.put("amex_auth_sign", request.getParameter("amex_auth_sign"));
			
			MerchantFactory m = new MerchantFactory();
			boolean ok = m.newMerchantCase(post, "put up", oSecUserDao.getLogonId(), oSecUserDao.getGroupCode(), oSecUserDao.getCountryCode());
			if(ok == false){
				json_error(m.getMessage(), response);
				return null;
			}
			
			if(m.getMerchantID() == 0 || m.getCaseID() == 0) {
				json_error("Failed to add Business Detail.", response);
				return null;
			}
			
			JSONObject data = new JSONObject();
			data.put("merchant_id", EncryptionHelper.encryptEncodeURL(m.getMerchantID()+""));
			data.put("case_id", EncryptionHelper.encryptEncodeURL(m.getCaseID() + ""));
			
			json_ok(response, data);
			
			return null;
		}
	
	public ActionForward edit_business_detail(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.edit_business_detail";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
			
		int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("merchant_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("app_type", request.getParameter("app_type"));
		post.put("ownership_status", request.getParameter("ownership_status"));
		post.put("registered_name", request.getParameter("registered_name"));
		post.put("registered_no", request.getParameter("registered_no"));
		post.put("desc", request.getParameter("nature_of_business"));
		post.put("mcc_code", request.getParameter("mcc_code"));
		post.put("paid_up_capital", request.getParameter("paid_up_capital"));
		post.put("recall_barcode", request.getParameter("recall_barcode_no"));
		post.put("year_in_business", request.getParameter("years_in_business"));
		post.put("avg_ticket_size", request.getParameter("avr_ticket_size"));
		post.put("acquirer", request.getParameter("current_acquirer"));
		post.put("curr_bank", request.getParameter("bank_name"));
		post.put("curr_acc_no", request.getParameter("current_acc_no"));
		post.put("curr_avg_deposit", request.getParameter("avr_monthly_deposit"));
		post.put("curr_avg_deposit_dtl", request.getParameter("monthly_deposit"));
		post.put("amex_auth_sign", request.getParameter("amex_auth_sign"));
		post.put("gst_registration", request.getParameter("gst_registration"));
		post.put("rmcd_approval_no", request.getParameter("rmcd_approval_no"));
		
		MerchantFactory m = new MerchantFactory();
		boolean ok = m.editMerchantCase(merchant_id, case_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(m.getMessage(), response);
			return null;
		}
		
		
		
		JSONObject data = new JSONObject();
		data.put("merchant_id", EncryptionHelper.encryptEncodeURL(merchant_id + ""));
		data.put("case_id", EncryptionHelper.encryptEncodeURL(case_id + ""));
		
		json_ok(response, data);
		
		return null;
	}
	
	public ActionForward create_match_trace(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_match_trace";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
			
		int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("merchant_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		int send_to_host = Integer.parseInt(request.getParameter("send_to_host"));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("app_type", request.getParameter("app_type"));
		post.put("ownership_status", request.getParameter("ownership_status"));
		post.put("match_trace", request.getParameter("match_trace"));
		
		MerchantFactory m = new MerchantFactory();
		boolean ok = m.editMerchantCase(merchant_id, case_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(m.getMessage(), response);
			return null;
		}
		
		
//		if(send_to_host > 0){
//			ok = m.sendMatchTrace(merchant_id, case_id, post, oSecUserDao.getLogonId(), oSecUserDao.getGroupCode());
//			if(ok == false){
//				json_error(m.getMessage(), response);
//				return null;
//			}
//		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_outlet_detail(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_outlet_detail";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("merchant_id", EncryptionHelper.decrypt(request.getParameter("merchant_id")));
		post.put("case_id", EncryptionHelper.decrypt(request.getParameter("case_id")));
		post.put("registered_name", request.getParameter("registered_name"));
		post.put("registered_no", request.getParameter("registered_no"));
		post.put("gst_registration", request.getParameter("gst_registration"));
		post.put("rmcd_approval_no", request.getParameter("rmcd_approval_no"));
		post.put("trading_name", request.getParameter("trading_name"));
		post.put("contact_person", request.getParameter("contact_person"));
		post.put("designation", request.getParameter("designation"));
		post.put("email", request.getParameter("email"));
		post.put("telephone_no", request.getParameter("telephone_no"));
		post.put("fax_no", request.getParameter("fax_no"));
		post.put("esa_ref_no", request.getParameter("esa_ref_no"));
		post.put("no_of_terminal", request.getParameter("no_of_terminal"));
		post.put("terminal_rental_fee", request.getParameter("terminal_rental_fee"));
		post.put("terminal_owner", request.getParameter("terminal_owner"));
		post.put("license_no", request.getParameter("license_no"));
		post.put("license_type", request.getParameter("license_type"));
		post.put("state", request.getParameter("state"));
		post.put("issuer", request.getParameter("issuer"));
		post.put("expiry_date", request.getParameter("expiry_date"));
		post.put("risk_level", request.getParameter("risk_level"));
		post.put("terminal_deposit_wired", request.getParameter("terminal_deposit_wired"));
		post.put("terminal_deposit_wireless", request.getParameter("terminal_deposit_wireless"));
		post.put("terminal_rental_deposit_wired", request.getParameter("terminal_rental_deposit_wired"));
		post.put("terminal_rental_deposit_wireless", request.getParameter("terminal_rental_deposit_wireless"));
		post.put("advance_terminal_rental", request.getParameter("advance_terminal_rental"));
		post.put("risk_level", request.getParameter("risk_level"));
		post.put("total_cheque_amt", request.getParameter("total_cheque_amt"));
		post.put("bank_issuer", request.getParameter("bank_issuer"));
		post.put("bank_branch", request.getParameter("bank_branch"));
		post.put("cheque_no", request.getParameter("cheque_no"));
		post.put("cheque_date", request.getParameter("cheque_date"));
		post.put("terminal_id", request.getParameter("terminal_id"));
		post.put("terminal_id_no", request.getParameter("terminal_id_no"));
		post.put("terminal_install_date", request.getParameter("terminal_install_date"));
		
		OutletFactory o = new OutletFactory();
		boolean ok = o.newCaseOutlet(post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		int outlet_id = (int)o.getOutletID();
		
		ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
		if(c_outlets == null){
			System.out.println(o.getMessage());
			return null;
		}
		
		
		String payment_info = "";
		String statement_opt = "";
		String other_info = "";
		String address = "";
		String address2 = "";
		String address3 = "";
		String mdr = "";
		
		if(c_outlets.size() > 0) {
			payment_info = c_outlets.get(0).getOutlet().getPaymentOpt();
			statement_opt = c_outlets.get(0).getOutlet().getStatementOpt();
			other_info = c_outlets.get(0).getOutlet().getOtherInfo();
			address = c_outlets.get(0).getOutlet().getAddress();
			address2 = c_outlets.get(0).getOutlet().getAddress2();
			address3 = c_outlets.get(0).getOutlet().getAddress3();
			mdr = c_outlets.get(0).getOutlet().getMDRRate();
		}
		
		
		TreeMap<String, String> post2 = new TreeMap<String, String>();
		post2.put("payment_info", payment_info);
		post2.put("statement_opt", statement_opt);
		post2.put("other_info", other_info);
		post2.put("physical_address", address);
		post2.put("payment_address", address2);
		post2.put("correspondence_address", address3);
		post2.put("mdr", mdr);
		
		ok = o.editCaseOutlet(case_id, outlet_id, post2, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		if(o.getOutletID() == 0) {
			json_error("Failed to add Outlet Detail.", response);
			return null;
		}
		
		
		JSONObject data = new JSONObject();
		data.put("outlet_id", EncryptionHelper.encryptEncodeURL(o.getOutletID() + ""));
		
		json_ok(response, data);
		
		return null;
	}
	
	public ActionForward edit_outlet_detail(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.edit_outlet_detail";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("registered_name", request.getParameter("registered_name"));
		post.put("registered_no", request.getParameter("registered_no"));
		post.put("gst_registration", request.getParameter("gst_registration"));
		post.put("rmcd_approval_no", request.getParameter("rmcd_approval_no"));
		post.put("trading_name", request.getParameter("trading_name"));
		post.put("contact_person", request.getParameter("contact_person"));
		post.put("designation", request.getParameter("designation"));
		post.put("email", request.getParameter("email"));
		post.put("telephone_no", request.getParameter("telephone_no"));
		post.put("fax_no", request.getParameter("fax_no"));
		post.put("esa_ref_no", request.getParameter("esa_ref_no"));
		post.put("no_of_terminal", request.getParameter("no_of_terminal"));
		post.put("terminal_rental_fee", request.getParameter("terminal_rental_fee"));
		post.put("terminal_owner", request.getParameter("terminal_owner"));
		post.put("license_no", request.getParameter("license_no"));
		post.put("license_type", request.getParameter("license_type"));
		post.put("state", request.getParameter("state"));
		post.put("issuer", request.getParameter("issuer"));
		post.put("expiry_date", request.getParameter("expiry_date"));
		post.put("terminal_deposit_wired", request.getParameter("terminal_deposit_wired"));
		post.put("terminal_deposit_wireless", request.getParameter("terminal_deposit_wireless"));
		post.put("terminal_rental_deposit_wired", request.getParameter("terminal_rental_deposit_wired"));
		post.put("terminal_rental_deposit_wireless", request.getParameter("terminal_rental_deposit_wireless"));
		post.put("advance_terminal_rental", request.getParameter("advance_terminal_rental"));
		post.put("risk_level", request.getParameter("risk_level"));
		post.put("total_cheque_amt", request.getParameter("total_cheque_amt"));
		post.put("bank_issuer", request.getParameter("bank_issuer"));
		post.put("bank_branch", request.getParameter("bank_branch"));
		post.put("cheque_no", request.getParameter("cheque_no"));
		post.put("cheque_date", request.getParameter("cheque_date"));
		post.put("terminal_id", request.getParameter("terminal_id"));
		post.put("terminal_id_no", request.getParameter("terminal_id_no"));
		post.put("terminal_install_date", request.getParameter("terminal_install_date"));
		
		OutletFactory o = new OutletFactory();
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_payment_info(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_payment_info";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("payment_info", request.getParameter("payment_info"));
		
		OutletFactory o = new OutletFactory();
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_statement_opt(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_statement_opt";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("statement_opt", request.getParameter("statement_opt"));
		
		OutletFactory o = new OutletFactory();
		
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		String other_info = c_outlet.getOutlet().getOtherInfo();
		JSONObject obj_other_info = null;
		
		if(other_info.length() > 0){
			obj_other_info = (JSONObject)  JSONValue.parse(other_info);
		} else {
			obj_other_info = new JSONObject();
			obj_other_info.put("officer_code", "");
			obj_other_info.put("user_code_1", "");
			obj_other_info.put("user_code_2", "");
			obj_other_info.put("user_code_3", "");
			obj_other_info.put("chain_merchant", "000000000");
			obj_other_info.put("hierarchy_no", "");
			obj_other_info.put("level", "");
			obj_other_info.put("servicing_rep", "");
			obj_other_info.put("sales_rep", "");
			obj_other_info.put("level_5", "");
			obj_other_info.put("level_6", "");
		}
		
		
		JSONObject obj_stmt_info = (JSONObject)  JSONValue.parse(post.get("statement_opt"));
		String visa_1 = obj_stmt_info.get("visa_1").toString();
		
		if(visa_1.equals("By Merchant Portal Service")){
			obj_other_info.put("user_code_3", "MP");
		} else if(visa_1.equals("By M2E Service")){
			obj_other_info.put("user_code_3", "98");
		} else if(visa_1.equals("By e-Commerce Report")){
			obj_other_info.put("user_code_3", "99");
		}
		
		post.put("other_info", obj_other_info.toString());
		
		
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_other_info(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_other_info";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("other_info", request.getParameter("other_info"));
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			JSONObject mdr = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
			JSONObject other_info = (JSONObject) JSONValue.parse(request.getParameter("other_info"));
			
			mdr.put("5", other_info.get("hierarchy_no"));
			mdr.put("277", other_info.get("chain_merchant"));
			mdr.put("337", other_info.get("level_5"));
			mdr.put("343", other_info.get("level_6"));
			post.put("mdr", mdr.toString());
		}
		
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_physical_address(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_physical_address";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("physical_address", request.getParameter("address"));
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		if(c_outlet.getOutlet().getAddress2().length() <= 0){
			post.put("payment_address", request.getParameter("address"));
		}
		
		if(c_outlet.getOutlet().getAddress3().length() <= 0){
			post.put("correspondence_address", request.getParameter("address"));
		}
		
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_payment_address(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_payment_address";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("payment_address", request.getParameter("address"));
		
		OutletFactory o = new OutletFactory();
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_correspondence_address(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_correspondence_address";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("correspondence_address", request.getParameter("address"));
		
		OutletFactory o = new OutletFactory();
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_mdr(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_mdr";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("mdr", request.getParameter("mdr"));
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		JSONObject mdr = (JSONObject) JSONValue.parse(request.getParameter("mdr"));
		
		if(c_outlet.getOutlet().getOtherInfo().length() > 0){
			JSONObject other_info = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
			
			other_info.put("hierarchy_no", mdr.get("5"));
			other_info.put("chain_merchant", mdr.get("277"));
			other_info.put("level_5", mdr.get("337"));
			other_info.put("level_6", mdr.get("343"));
			post.put("other_info", other_info.toString());
		}
		
		if(mdr.containsKey("14")) {
			post.put("mid_pos", mdr.get("14").toString());
		}
		
		if(mdr.containsKey("283")) {
			post.put("mid_amex", mdr.get("283").toString());
		}
		
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}

	public ActionForward create_esapl(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		final String PROG_ID="SubmitAppAction.create_esapl";
	
		//System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}
	
		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;
	
			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		//System.out.println(this.authorized(request));
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("esapl", request.getParameter("esapl"));
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		if(c_outlet.getOutlet().getOtherInfo().length() > 0){
			JSONObject esapl = (JSONObject) JSONValue.parse(request.getParameter("esapl"));
			JSONObject other_info = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
			
			other_info.put("chain_merchant", esapl.get("277"));
			post.put("other_info", other_info.toString());
		}
		
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_ezypay(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		final String PROG_ID="SubmitAppAction.create_ezypay";

		//System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		//System.out.println(this.authorized(request));
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("ezypay", request.getParameter("ezypay"));
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		if(c_outlet.getOutlet().getOtherInfo().length() > 0){
			JSONObject ezypay = (JSONObject) JSONValue.parse(request.getParameter("ezypay"));
			JSONObject other_info = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
			
			other_info.put("chain_merchant", ezypay.get("277"));
			post.put("other_info", other_info.toString());
		}
		
		
		boolean ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	
	public ActionForward outlet_delete(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.outlet_delete";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		OutletFactory o = new OutletFactory();
		boolean ok = o.deleteCaseOutlet(case_id, outlet_id, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward document_delete(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.document_delete";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int doc_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("doc_id")));
		
		boolean ok = CasemastFactory.document_delete(doc_id, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		
		return null;
	}
	
	
	public ActionForward create_document_checklist(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_document_checklist";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("merchant_id")));
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		String notify_email = request.getParameter("notify_email");
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("document_checklist", request.getParameter("document_checklist"));
		
		MerchantFactory m = new MerchantFactory();
		boolean ok = m.editCaseDocumentChecklist(case_id, post.get("document_checklist"), oSecUserDao.getLogonId());
		if(ok == false){
			json_error(m.getMessage(), response);
			return null;
		}
		
		
		if(notify_email.equals("Y")){
			Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
			if(m_case == null){
				json_error(CasemastFactory.getMessage(), response);
				return null;
			}
			
			
			request.setAttribute("m_case", m_case);
			
			
			String strEMerchant = (String) session.getAttribute(Constants.MERCHANT_KEY);
			UserDao userdao = SecUsersHome.getInstance().getUser(strEMerchant, m_case.getCreatedBy());
			
			String email_addr = userdao.getEmail();
			if(email_addr.isEmpty()) {
				json_error("[" + m_case.getCreatedBy() + "] does not have an email address.", response);
				return null;
			}
			
			CharArrayWriterResponse customResponse1 = new CharArrayWriterResponse(response);
			request.getRequestDispatcher("jsp/map/_document_checklist.jsp").forward(request, customResponse1);
			
			String content = customResponse1.getOutput();
			System.out.println("jsp/map/_document_checklist.jsp content: \r\n"+ content);
			
			if(content == null || content.trim().equalsIgnoreCase("")){
				System.out.println("create_document_checklinst - content empty, goto buildManualContent");
				content = buildManualContent(m_case);
			}
			String subject = "MAP Document Checklist";
			
			Notification n = new Notification();
			ok = n.createNotificationQueue(email_addr, "Document Checklist", subject, content, oSecUserDao.getLogonId());
			if(ok == false) {
				json_error(n.getMessage(), response);
				return null;
			}
		}
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward create_recommendation(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_recommendation";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		String s_arr[] = null;
		ArrayList<String> mod_arr = new ArrayList<String>();
		
		s_arr = SubmitAppAction.modApproval.split(",");
		for(String s : s_arr){
			mod_arr.add(s);
		}
		
		if(mod_arr.contains(this.iMod)) {
			String str_case_id   = request.getParameter("case_id");
			String str_outlet_id = request.getParameter("outlet_id");

			int case_id = Integer.parseInt(EncryptionHelper.decrypt(str_case_id));
			int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(str_outlet_id));
			String recom = request.getParameter("recom");
			
			OutletFactory o = new OutletFactory();
			boolean ok = o.editCaseOutletRecom(case_id, outlet_id, recom);
			if(ok == false){
				json_error(CasemastFactory.getMessage(), response);
				return null;
			}
			
			
			TreeMap<String, String> post = new TreeMap<String, String>();
			post.put("mdr", request.getParameter("mdr"));
			
			CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
			if(c_outlet == null){
				json_error(o.getMessage(), response);
				return null;
			}
			
			JSONObject mdr = (JSONObject) JSONValue.parse(request.getParameter("mdr"));
			System.out.println("MDR : " + mdr.get("30"));
			if(c_outlet.getOutlet().getOtherInfo().length() > 0){
				JSONObject other_info = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
				
				other_info.put("hierarchy_no", mdr.get("5"));
				other_info.put("chain_merchant", mdr.get("277"));
				other_info.put("level_5", mdr.get("337"));
				other_info.put("level_6", mdr.get("343"));
				post.put("other_info", other_info.toString());
			}
			
			if(mdr.containsKey("14")) {
				post.put("mid_pos", mdr.get("14").toString());
			}
			
			if(mdr.containsKey("283")) {
				post.put("mid_amex", mdr.get("283").toString());
			}
			
			ok = o.editCaseOutlet(case_id, outlet_id, post, oSecUserDao.getLogonId());
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
		}
		
		
		json_ok(response);
		
		return null;
	}
	
	public ActionForward update_cardlink(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.update_cardlink";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
			
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		try {
			int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
			AutoScript.generate(case_id, outlet_id, oSecUserDao.getLogonId(), oSecUserDao.getGroupCode());
		} catch (Exception e) {
			e.printStackTrace();
			json_error(e.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward clear_cardlink(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.clear_cardlink";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
			
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		int outlet_id = Integer.parseInt(request.getParameter("outlet_id"));
		
		try {
			AutoScript.clear(case_id, oSecUserDao.getLogonId(), oSecUserDao.getGroupCode());
		} catch (Exception e) {
			e.printStackTrace();
			json_error(e.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward get_email_address(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.get_email_address";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
			
		
		String vendor = request.getParameter("vendor");
		vendor = vendor.replace(" ","_");
		vendor = vendor.toLowerCase();
		
		try {
			InputStream stream = SubmitAppAction.class.getResourceAsStream(CONFIG_FILE);
			if (stream != null){
				appCfg.load(stream);
			} else {
				System.out.println("SubmitAppAction Input Stream is NULL");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		String email_addr = appCfg.getProperty(vendor + "_email");
		
		JSONObject data = new JSONObject();
		data.put("email", email_addr);
		
		json_ok(response, data);
		return null;
	}
	
	public ActionForward create_pos_form(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_pos_form";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		//String strCaseId = request.getParameter("case_id");
		//String strOultetId = request.getParameter("outlet_id");
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		String refference_no = request.getParameter("app_no");
		
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("pos_form", request.getParameter("pos_form"));
		
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		JSONObject mdr_obj = new JSONObject();
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		
		JSONObject pos_form_obj = new JSONObject();
		if(c_outlet.getPosForm().length() > 0){
			pos_form_obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
		}
		
		
		JSONObject vendor_arr = new JSONObject();;
		if(pos_form_obj.get("vendor_arr") != null){
			vendor_arr = (JSONObject) pos_form_obj.get("vendor_arr");
		}
		
		
		JSONObject obj = (JSONObject) JSONValue.parse(request.getParameter("pos_form"));
		JSONObject vendor_details = (JSONObject) obj.get("vendor_details");
		JSONArray tid_facilities = new JSONArray();
		
		if(vendor_details.containsKey("name")) {
			JSONObject facilities = (JSONObject) vendor_details.get("mdr_facilities");
			JSONObject facility_tids = new JSONObject();
			
			JSONObject pos_ezypay_facilities = (JSONObject) vendor_details.get("pos_ezypay_facilities");
			JSONObject amex_ezypay_facilities = (JSONObject) vendor_details.get("amex_ezypay_facilities");
			
			
			String in_mid_e3 = mdr_obj.get("190") == null ? "" : mdr_obj.get("190").toString();
			String in_mid_e6 = mdr_obj.get("191") == null ? "" : mdr_obj.get("191").toString();
			String in_mid_e9 = mdr_obj.get("192") == null ? "" : mdr_obj.get("192").toString();
			String in_mid_e12 = mdr_obj.get("193") == null ? "" : mdr_obj.get("193").toString();
			String in_mid_e18 = mdr_obj.get("194") == null ? "" : mdr_obj.get("194").toString();
			String in_mid_e24 = mdr_obj.get("195") == null ? "" : mdr_obj.get("195").toString();
			String in_mid_e30 = mdr_obj.get("196") == null ? "" : mdr_obj.get("196").toString();
			String in_mid_e36 = mdr_obj.get("197") == null ? "" : mdr_obj.get("197").toString();
			
			String in_mid_e3_amex = mdr_obj.get("411") == null ? "" : mdr_obj.get("411").toString();
			String in_mid_e6_amex = mdr_obj.get("412") == null ? "" : mdr_obj.get("412").toString();
			String in_mid_e9_amex = mdr_obj.get("413") == null ? "" : mdr_obj.get("413").toString();
			String in_mid_e12_amex = mdr_obj.get("414") == null ? "" : mdr_obj.get("414").toString();
			String in_mid_e18_amex = mdr_obj.get("415") == null ? "" : mdr_obj.get("415").toString();
			String in_mid_e24_amex = mdr_obj.get("416") == null ? "" : mdr_obj.get("416").toString();
			String in_mid_e30_amex = mdr_obj.get("417") == null ? "" : mdr_obj.get("417").toString();
			String in_mid_e36_amex = mdr_obj.get("418") == null ? "" : mdr_obj.get("418").toString();
			
			
			String[] arr = new String[] {"POS", "DCC", "MO", "TO", "RPS", "E-Commerce", "M2U", "ORS"};
			String[] arr_type = new String[] {"Wired", "Wireless", "MPOS"};
			String[] arr_ezpay = new String[] {"E3", "E6", "E9", "E12", "E18", "E24", "E36"};
			
			for(String s : arr){
				if(facilities.get(s) != null){
					JSONObject item_type = (JSONObject) facilities.get(s);
					JSONObject facility_types = new JSONObject();
					
					for(String t  : arr_type) {
						JSONObject item = (JSONObject) item_type.get(t);
						
						String mid_pos = item.get("mid_no").toString();
						String mid_amex = item.get("mid_no2").toString();
						
						if(item.get("first_tid").toString().length() > 0){
							long tid_start = Long.parseLong(item.get("first_tid").toString());
							int tid_items = Integer.parseInt(item.get("tid_items").toString());
							
							JSONArray tid_arr = new JSONArray();
							
							for(int n = 0; n < tid_items; n++){
								long tid_no = tid_start + n;
								
								JSONObject tid_item = new JSONObject();
								tid_item.put("mid_no", item.get("mid_no").toString());
								tid_item.put("mid_no2", item.get("mid_no2").toString());
								tid_item.put("tid_no", Long.toString(tid_no));
								
								tid_arr.add(tid_item);
								tid_facilities.add(tid_item);
								
								
								
								JSONObject pos_ezypay_arr = new JSONObject();
								JSONObject pos_ezypay_item = new JSONObject();
								JSONObject amex_ezypay_arr = new JSONObject();
								JSONObject amex_ezypay_item = new JSONObject();
								
								if(pos_ezypay_facilities.containsKey(Long.toString(tid_no))){
									pos_ezypay_arr = (JSONObject) pos_ezypay_facilities.get(Long.toString(tid_no));
								}
								
								if(amex_ezypay_facilities.containsKey(Long.toString(tid_no))){
									amex_ezypay_arr = (JSONObject) amex_ezypay_facilities.get(Long.toString(tid_no));
								}
								
								for(String ezpay_month : arr_ezpay) {
									String ezpay_mid = "";
									String ezpay_mid_amex = "";
									int ezpay_n = 0;
									
									if(ezpay_month.equals("E3")) {
										ezpay_mid = in_mid_e3;
										ezpay_mid_amex = in_mid_e3_amex;
										ezpay_n = 3;
									} else if(ezpay_month.equals("E6")) {
										ezpay_mid = in_mid_e6;
										ezpay_mid_amex = in_mid_e6_amex;
										ezpay_n = 6;
									} else if(ezpay_month.equals("E9")) {
										ezpay_mid = in_mid_e9;
										ezpay_mid_amex = in_mid_e9_amex;
										ezpay_n = 9;
									} else if(ezpay_month.equals("E12")) {
										ezpay_mid = in_mid_e12;
										ezpay_mid_amex = in_mid_e12_amex;
										ezpay_n = 12;
									} else if(ezpay_month.equals("E18")) {
										ezpay_mid = in_mid_e18;
										ezpay_mid_amex = in_mid_e18_amex;
										ezpay_n = 18;
									} else if(ezpay_month.equals("E24")) {
										ezpay_mid = in_mid_e24;
										ezpay_mid_amex = in_mid_e24_amex;
										ezpay_n = 24;
									} else if(ezpay_month.equals("E30")) {
										ezpay_mid = in_mid_e30;
										ezpay_mid_amex = in_mid_e30_amex;
										ezpay_n = 30;
									} else if(ezpay_month.equals("E36")) {
										ezpay_mid = in_mid_e36;
										ezpay_mid_amex = in_mid_e36_amex;
										ezpay_n = 36;
									} else {
										continue;
									}
									
									
									if(mid_pos.length() > 0 && ezpay_mid.length() > 0){
										if(pos_ezypay_arr.get(ezpay_month) != null) {
											pos_ezypay_item = (JSONObject) pos_ezypay_arr.get(ezpay_month);
										} else {
											pos_ezypay_item = new JSONObject();
											pos_ezypay_item.put("first_tid", "");
										}
										
										pos_ezypay_item.put("tid_no", Long.toString(tid_no));
										pos_ezypay_item.put("type", t);
										pos_ezypay_item.put("ezypay_plan", ezpay_n);
										pos_ezypay_item.put("mid_no", ezpay_mid);
										
										pos_ezypay_arr.put(ezpay_month, pos_ezypay_item);
									}
									else {
										pos_ezypay_arr.remove(ezpay_month);
									}
										
									
									if(mid_amex.length() > 0 && ezpay_mid_amex.length() > 0){
										if(amex_ezypay_arr.get(ezpay_month) != null) {
											amex_ezypay_item = (JSONObject) amex_ezypay_arr.get(ezpay_month);
										} else {
											amex_ezypay_item = new JSONObject();
											amex_ezypay_item.put("first_tid", "");
										}
										
										if(ezpay_mid_amex.startsWith("01")) {
											ezpay_mid_amex = ezpay_mid_amex.replaceFirst("01", "920");
										}
										
										amex_ezypay_item.put("tid_no", Long.toString(tid_no));
										amex_ezypay_item.put("type", t);
										amex_ezypay_item.put("ezypay_plan", ezpay_n);
										amex_ezypay_item.put("mid_no", ezpay_mid_amex);
										
										amex_ezypay_arr.put(ezpay_month, amex_ezypay_item);
									}
									else {
										amex_ezypay_arr.remove(ezpay_month);
									}
								}
								
								
								pos_ezypay_facilities.put(Long.toString(tid_no), pos_ezypay_arr);
								amex_ezypay_facilities.put(Long.toString(tid_no), amex_ezypay_arr);
								
								
							}
							
							
							facility_types.put(t, tid_arr);
						}
						
						
					}
					
					facility_tids.put(s, facility_types);
				}
			}
			
			vendor_details.put("facility_tids", facility_tids);
			vendor_details.put("pos_ezypay_facilities", pos_ezypay_facilities);
			vendor_details.put("amex_ezypay_facilities", amex_ezypay_facilities);
			
			/*if(vendor_details.get("serial_no").toString().equals("")) {
				String serial_no = o.generateVendorFormSerialNo();
				if(serial_no != null) {
					vendor_details.put("serial_no", serial_no);
				}
			}*/
			String serial_no = o.generateVendorFormSerialNo(case_id, outlet_id, refference_no, vendor_details.get("name").toString());
			if(serial_no != null) {
				vendor_details.put("serial_no", serial_no);
			}
			
			vendor_arr.put(vendor_details.get("name"), vendor_details);
		}
		
		obj.put("vendor_arr", vendor_arr);
		obj.remove("vendor_details");
		
		
		JSONObject appendix = new JSONObject();
		
		if(pos_form_obj.get("appendix") != null){
			appendix = (JSONObject) pos_form_obj.get("appendix");
		}
		
		
		if(obj.get("request_type").toString().equals("Tag-on")) {
			String bank_name = obj.get("bank").toString();
			
			JSONObject appendix2 = new JSONObject();
			for(Object s : appendix.keySet()) {
				String s1 = String.valueOf(s);
				
				if(s1.startsWith("Tag On - ")) {
					if(s1.equals("Tag On - " + bank_name)){
						appendix2.put(s1, appendix.get(s1));
					}
				} else {
					appendix2.put(s1, appendix.get(s1));
				}
			}
			
			appendix = appendix2;
			
			JSONObject appdx_bank = new JSONObject();
			
			if(appendix.containsKey("Tag On - " + bank_name) == false){
				appdx_bank.put("name", bank_name + " - Maybank Vendor POS Form");
				appdx_bank.put("last_sent", "");
			}
			else {
				appdx_bank = (JSONObject) appendix.get("Tag On - " + bank_name);
			}
			
			appdx_bank.put("modified_by", oSecUserDao.getLogonId());
			appdx_bank.put("modified_date", new Date().getTime());
			
			appendix.put("Tag On - " + bank_name, appdx_bank);
		}
		else {
			JSONObject appendix2 = new JSONObject();
			for(Object s : appendix.keySet()) {
				String s1 = String.valueOf(s);
				
				if(s1.startsWith("Tag On - ") == false) {
					appendix2.put(s1, appendix.get(s1));
				}
			}
			
			appendix = appendix2;
		}
		
		
		if(vendor_details.containsKey("email") && vendor_details.get("email").toString().equals("") == false) {
			String vendor_name = vendor_details.get("name").toString();
			String vendor_name2 = vendor_details.get("name2").toString();
			
			JSONObject appdx_vendor = new JSONObject();
			
			if(appendix.containsKey("Vendor - " + vendor_name) == false){
				appdx_vendor.put("name", vendor_name2 + " - Maybank Vendor POS Form");
				appdx_vendor.put("last_sent", "");
			}
			else {
				appdx_vendor = (JSONObject) appendix.get("Vendor - " + vendor_name);
				appdx_vendor.put("name", vendor_name2 + " - Maybank Vendor POS Form");
			}
			
			appdx_vendor.put("modified_by", oSecUserDao.getLogonId());
			appdx_vendor.put("modified_date", new Date().getTime());
			
			appendix.put("Vendor - " + vendor_name, appdx_vendor);
			
		}
		else {
			JSONObject appendix2 = new JSONObject();
			for(Object s : appendix.keySet()) {
				String s1 = String.valueOf(s);
				
				if(s1.startsWith("Vendor - ") == false) {
					appendix2.put(s1, appendix.get(s1));
				}
			}
			
			appendix = appendix2;
		}
		
		
		JSONArray card_types = new JSONArray();
		
		if(vendor_details.get("card_types") != null){
			card_types = (JSONArray) vendor_details.get("card_types");
		}
		
		
		if(card_types.contains("Union Pay")){
			JSONObject appdx_unionpay = new JSONObject();
			
			if(appendix.containsKey("Union Pay")) {
				appdx_unionpay = (JSONObject) appendix.get("Union Pay");
			}
			
			
			JSONObject appdx_unionpay_detail = new JSONObject();
			
			if(appdx_unionpay.containsKey(vendor_details.get("name"))){
				appdx_unionpay_detail = (JSONObject) appdx_unionpay.get(vendor_details.get("name"));
			}
			else {
				appdx_unionpay_detail.put("name", "China Union Pay Submission");
				appdx_unionpay_detail.put("vendor", vendor_details.get("name"));
				appdx_unionpay_detail.put("last_sent", "");
			}
			
			
			appdx_unionpay_detail.put("modified_by", oSecUserDao.getLogonId());
			appdx_unionpay_detail.put("modified_date", new Date().getTime());
			
			appdx_unionpay.put(vendor_details.get("name"), appdx_unionpay_detail);
			appendix.put("Union Pay", appdx_unionpay);
		}
		else {
			if(appendix.containsKey("Union Pay")){
				JSONObject appdx_unionpay = (JSONObject) appendix.get("Union Pay");
				
				if(appdx_unionpay.containsKey(vendor_details.get("name"))){
					appdx_unionpay.remove(vendor_details.get("name"));
				}
				
				if(appdx_unionpay.size() <= 0){
					appendix.remove("Union Pay");
				}
			}
		}
		
		
		JSONArray edc_programme = new JSONArray();
		
		if(obj.get("edc_programme") != null){
			edc_programme = (JSONArray) obj.get("edc_programme");
		}
		
		if(edc_programme.contains("DCC")){
			JSONObject appdx_dcc = new JSONObject();
			
			if(appendix.containsKey("DCC") == false){
				appdx_dcc.put("name", "Travelex DCC Order");
				appdx_dcc.put("last_sent", "");
			}
			else {
				appdx_dcc = (JSONObject) appendix.get("DCC");
			}
			
			appdx_dcc.put("modified_by", oSecUserDao.getLogonId());
			appdx_dcc.put("modified_date", new Date().getTime());
			
			appendix.put("DCC", appdx_dcc);
		}
		else {
			if(appendix.containsKey("DCC")){
				appendix.remove("DCC");
			}
		}
		
		
		if(vendor_details.get("diners_select") != null && vendor_details.get("diners_select").toString().equals("Y")){
			JSONObject appdx_diners = new JSONObject();
			
			if(appendix.containsKey("DINERS") == false){
				appdx_diners.put("name", "DINERS - Maybank Vendor POS Form");
				appdx_diners.put("last_sent", "");
			}
			else {
				appdx_diners = (JSONObject) appendix.get("DINERS");
			}
			
			appdx_diners.put("modified_by", oSecUserDao.getLogonId());
			appdx_diners.put("modified_date", new Date().getTime());
			
			appendix.put("DINERS", appdx_diners);
		} else {
			appendix.remove("DINERS");
		}
		
		
		if(vendor_details.get("aeon_select") != null && vendor_details.get("aeon_select").toString().equals("Y")){
			JSONObject appdx_aeon = new JSONObject();
			
			if(appendix.containsKey("AEON") == false){
				appdx_aeon.put("name", "AEON - Maybank Vendor POS Form");
				appdx_aeon.put("last_sent", "");
			}
			else {
				appdx_aeon = (JSONObject) appendix.get("AEON");
			}
			
			appdx_aeon.put("modified_by", oSecUserDao.getLogonId());
			appdx_aeon.put("modified_date", new Date().getTime());
			
			appendix.put("AEON", appdx_aeon);
		} else {
			appendix.remove("AEON");
		}
		
		
		if(vendor_details.get("genting_select") != null && vendor_details.get("genting_select").toString().equals("Y")){
			JSONObject appdx_genting = new JSONObject();
			
			if(appendix.containsKey("GENTING") == false){
				appdx_genting.put("name", "GENTING - Maybank Vendor POS Form");
				appdx_genting.put("last_sent", "");
			}
			else {
				appdx_genting = (JSONObject) appendix.get("GENTING");
			}
			
			appdx_genting.put("modified_by", oSecUserDao.getLogonId());
			appdx_genting.put("modified_date", new Date().getTime());
			
			appendix.put("GENTING", appdx_genting);
		} else {
			appendix.remove("GENTING");
		}
		
		obj.put("appendix", appendix);
		obj.put("modified_date", new Date().getTime());
		obj.put("modified_by", oSecUserDao.getLogonId());
		
		
		int terminalNum = tid_facilities.size();
		String terminalIdStr = "";
		String sep = "";
		
		for(Object tidObj : tid_facilities) {
			JSONObject tidObj2 = (JSONObject) tidObj;
			
			terminalIdStr += sep + tidObj2.get("tid_no");
			sep = ",";
		}
		
		boolean ok = o.editCaseOutletPOSForm(case_id, outlet_id, obj.toString(), Integer.toString(terminalNum), terminalIdStr);
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		if(vendor_details.containsKey("name")) {
			ok = o.editPOSFormSerialNo(case_id, outlet_id, vendor_details.get("name").toString(), vendor_details.get("serial_no").toString());
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
		}
		
		
		json_ok(response);
		return null;
	}
	
	public ActionForward create_notification(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
			final String PROG_ID="SubmitAppAction.create_notification";

			System.out.println(PROG_ID + " : BEGIN");
			HttpSession session = request.getSession(false);
			
			//check session condition
			if (session == null){
				//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
				json_error("Session not found.", response);
				return null;
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
				String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
				session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
				if (DEBUG) System.out.println("... Javascript not enable");
				//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
				json_error("Javascript not enabled.", response);
				return null;
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
				if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
					if (DEBUG) System.out.println("sessionstatus !=null 2");
					String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
					session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
					
					json_error("sessionstatus !=null 2", response);
					return null;

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				//return mapping.findForward(strFwd);
				json_error("Your session has expired", response);
				return null;
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(this.authorized(request) == false){
				json_error("Unauthorized access.", response);
				return null;
			}

			int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
			int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
			
			TreeMap<String, String> post = new TreeMap<String, String>();
			post.put("pos_form", request.getParameter("pos_form"));
			
			
			OutletFactory o = new OutletFactory();
			CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
			
			if(c_outlet == null){
				json_error(o.getMessage(), response);
				return null;
			}
			
			
			JSONObject mdr_obj = new JSONObject();
			if(c_outlet.getOutlet().getMDRRate().length() > 0){
				mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
			}
			
			
			JSONObject pos_form_obj = new JSONObject();
			if(c_outlet.getPosForm().length() > 0){
				pos_form_obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
			}
			
			
			JSONObject vendor_arr = new JSONObject();;
			if(pos_form_obj.get("vendor_arr") != null){
				vendor_arr = (JSONObject) pos_form_obj.get("vendor_arr");
			}
			
			
			JSONObject obj = (JSONObject) JSONValue.parse(request.getParameter("pos_form"));
			JSONObject vendor_details = (JSONObject) obj.get("vendor_details");
			JSONArray tid_facilities = new JSONArray();
			
			obj.put("vendor_arr", vendor_arr);
			obj.remove("vendor_details");

			int terminalNum = tid_facilities.size();
			
			String terminalIdStr = "";
			String sep = "";
			
			for(Object tidObj : tid_facilities) {
				JSONObject tidObj2 = (JSONObject) tidObj;
				
				terminalIdStr += sep + tidObj2.get("tid_no");
				sep = ",";
			}
			
			boolean ok = o.editCaseOutletPOSForm(case_id, outlet_id, obj.toString(), Integer.toString(terminalNum), terminalIdStr);
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
			
			if(vendor_details.containsKey("name")) {
				ok = o.editPOSFormSerialNo(case_id, outlet_id, vendor_details.get("name").toString(), vendor_details.get("serial_no").toString());
				/*if(ok == false){
					json_error(o.getMessage(), response);
					return null;
				}*/
				
				if(vendor_details.containsKey("email") && vendor_details.get("email").toString().equals("") == false) {

					String vendor_name2 = vendor_details.get("name2").toString();
					String emails = vendor_details.get("email").toString();
					String serial_no = vendor_details.get("serial_no").toString();

					Notification n = new Notification();

					ok = n.emailVendorPOS(oSecUserDao.getLogonId(), emails, vendor_name2, serial_no, "vendoremail");
					if(ok == false){
						json_error(n.getMessage(), response);
						return null;
					}
				}
			}

			json_ok(response);
			return null;
		}
		
		
	public ActionForward delete_pos_vendor(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.delete_pos_vendor";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		String strCaseId = request.getParameter("case_id");
		String strOutletId = request.getParameter("outlet_id");
		String strVendorName = request.getParameter("vendor_name");
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		String vendor_name = EncryptionHelper.decrypt(request.getParameter("vendor_name"));
		
		OutletFactory o = new OutletFactory();
		ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
		if(c_outlets == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
		
		if(obj.get("vendor_arr") != null){
			JSONObject vendor_arr = (JSONObject) obj.get("vendor_arr");
			
			if(vendor_arr.containsKey(vendor_name)){
				vendor_arr.remove(vendor_name);
			}
			
			obj.put("vendor_arr", vendor_arr);
			
			
			JSONObject appendix = new JSONObject();
			if(obj.get("appendix") != null){
				appendix = (JSONObject) obj.get("appendix");
			}
			
			if(appendix.containsKey("Union Pay")){
				JSONObject appdx_unionpay = (JSONObject) appendix.get("Union Pay");
				
				if(appdx_unionpay.containsKey(vendor_name)){
					appdx_unionpay.remove(vendor_name);
				}
				
				if(appdx_unionpay.size() <= 0){
					appendix.remove("Union Pay");
				}
			}
			
			
			obj.put("appendix", appendix);
			
			
			boolean ok = o.editCaseOutletPOSForm(case_id, outlet_id, obj.toString());
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
		} 
		
		json_ok(response);
		return null;
	}
	
	
	public ActionForward create_vendor_installation(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_vendor_installation";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		//String strOutletId = request.getParameter("outlet_id");
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("outlet_id")));
		 
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("pos_install", request.getParameter("pos_install"));
		
		JSONObject obj = (JSONObject) JSONValue.parse(request.getParameter("pos_install"));
		
		obj.put("modified_date", new Date().getTime());
		obj.put("modified_by", oSecUserDao.getLogonId());
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		JSONObject pos_install_arr = new JSONObject();
		JSONObject pos_install = new JSONObject();
		
		String vendor_name = obj.get("vendor_name").toString();
		String last_reschd_date = "";
		String last_status = "";
		
		if(c_outlet.getPosInstallation().length() > 0){
			pos_install_arr = (JSONObject) JSONValue.parse(c_outlet.getPosInstallation());
			if(pos_install_arr.get(vendor_name) != null){
				pos_install = (JSONObject) pos_install_arr.get(vendor_name);
			}
		}
		
		if(pos_install.get("reschedule_date") != null) {
			last_reschd_date = pos_install.get("reschedule_date").toString();
		}
		
		if(pos_install.get("inst_status") != null) {
			last_status = pos_install.get("inst_status").toString();
		}
		
		String remark = obj.get("remark").toString();
		String inst_status = obj.get("inst_status").toString();
		String reschd_date = obj.get("reschedule_date").toString();
		
		if(inst_status.equals("Reschedule") && reschd_date.equals(last_reschd_date) == false){
			remark += "*** Rescheduled to " + reschd_date;
		}
		else if(inst_status.equals("Successful") && inst_status.equals(last_status) == false){
			remark += "*** Successful";
		}
		
		if(remark.trim().equals("") == false){
			boolean ok = o.install_note_submit(case_id, outlet_id, vendor_name, remark, inst_status, reschd_date, oSecUserDao.getLogonId());
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
		}
		
		obj.remove("remark");
		
		pos_install_arr.put(vendor_name, obj);
		
		
		String terminal_install_date = "";
		String sep = "";
		
		for(Object v_name : pos_install_arr.keySet()) {
			JSONObject install_obj = (JSONObject) pos_install_arr.get(v_name);
			
			if(install_obj.get("last_install_date") != null) {
				terminal_install_date += sep + install_obj.get("vendor_name").toString() + " - " +  install_obj.get("last_install_date").toString();
				sep = ", ";
			}
		}
		
		boolean ok = o.editCaseOutletInstallForm(case_id, outlet_id, pos_install_arr.toString(), terminal_install_date);
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward create_appendix_dcc(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_appendix_dcc";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int case_id = Integer.parseInt(request.getParameter("case_id"));
		int outlet_id = Integer.parseInt(request.getParameter("outlet_id"));
		String notify_email = request.getParameter("notify_email");
		String email = request.getParameter("email");
		
		
		JSONObject obj = (JSONObject) JSONValue.parse(request.getParameter("appendix_data"));
		
		obj.put("modified_date", new Date().getTime());
		obj.put("modified_by", oSecUserDao.getLogonId());
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		JSONObject pos_form = new JSONObject();
		JSONObject appendix = new JSONObject();
		JSONObject appdx_dcc = new JSONObject();
		
		if(c_outlet.getPosForm().length() > 0){
			pos_form = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
			
			if(pos_form.get("appendix") != null) {
				appendix = (JSONObject) pos_form.get("appendix");
				
				if(appendix.get("DCC") != null){
					appdx_dcc = (JSONObject) appendix.get("DCC");
					appdx_dcc.put("data", obj);
					
					if(notify_email.equals("Y")){
						appdx_dcc.put("last_sent", new Date().getTime());
					}
					
					appendix.put("DCC", appdx_dcc);
				}
				
				pos_form.put("appendix", appendix);
			}
		}
		
		
		
		boolean ok = o.editCaseOutletPOSForm(case_id, outlet_id, pos_form.toString());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		if(notify_email.equals("Y")){
			Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
			if(m_case == null){
				json_error(CasemastFactory.getMessage(), response);
				return null;
			}
			
			
			
			c_outlet = o.getCaseOutlet(case_id, outlet_id);
			if(c_outlet == null){
				json_error(o.getMessage(), response);
				return null;
			}
			
			request.setAttribute("c_outlet", c_outlet);
			request.setAttribute("m_case", m_case);
			
			
			CharArrayWriterResponse customResponse1 = new CharArrayWriterResponse(response);
			request.getRequestDispatcher("jsp/map/_appendix_dcc.jsp").forward(request, customResponse1);
			
			String content = customResponse1.getOutput();
			System.out.println("jsp/map/_appendix_dcc.jsp content: \r\n"+ content);
			String subject = "Maybank Travelex DCC Order";
			
			Notification n = new Notification();
			ok = n.createNotificationQueue(email, "DCC Order", subject, content, oSecUserDao.getLogonId());
			if(ok == false) {
				json_error(n.getMessage(), response);
				return null;
			}
		}
		
		
		json_ok(response);
		return null;
	}
	
	
	public ActionForward create_appendix_unionpay(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_appendix_unionpay";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int case_id = Integer.parseInt(request.getParameter("case_id"));
		int outlet_id = Integer.parseInt(request.getParameter("outlet_id"));
		String vendor_name = request.getParameter("vendor_name");
		String notify_email = request.getParameter("notify_email");
		String email = request.getParameter("email");
		
		if(notify_email.equals("Y")){
			
			OutletFactory o = new OutletFactory();
			CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
			if(c_outlet == null){
				json_error(o.getMessage(), response);
				return null;
			}
			
			
			JSONObject pos_form = new JSONObject();
			JSONObject appendix = new JSONObject();
			JSONObject appdx_item = new JSONObject();
			
			if(c_outlet.getPosForm().length() > 0){
				pos_form = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
				
				if(pos_form.get("appendix") != null) {
					appendix = (JSONObject) pos_form.get("appendix");
					
					if(appendix.get("Union Pay") != null){
						appdx_item = (JSONObject) appendix.get("Union Pay");
						
						JSONObject appdx_item2 = new JSONObject();
						for(Object s : appdx_item.keySet()){
							JSONObject appdx_item_detail = (JSONObject) appdx_item.get(s);
							
							if(String.valueOf(s).equals(vendor_name)) {
								appdx_item_detail.put("last_sent", new Date().getTime());
							}
							
							appdx_item2.put(s, appdx_item_detail);
						}
						
						
						appendix.put("Union Pay", appdx_item2);
					}
					
					pos_form.put("appendix", appendix);
				}
			}
			
			
			
			boolean ok = o.editCaseOutletPOSForm(case_id, outlet_id, pos_form.toString());
			if(ok == false){
				json_error(o.getMessage(), response);
				return null;
			}
			
			
			Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
			if(m_case == null){
				json_error(CasemastFactory.getMessage(), response);
				return null;
			}
			
			
			
			c_outlet = o.getCaseOutlet(case_id, outlet_id);
			if(c_outlet == null){
				json_error(o.getMessage(), response);
				return null;
			}
			
			request.setAttribute("c_outlet", c_outlet);
			request.setAttribute("m_case", m_case);
			request.setAttribute("vendor_name", vendor_name);
			
			
			CharArrayWriterResponse customResponse1 = new CharArrayWriterResponse(response);
			request.getRequestDispatcher("jsp/map/_appendix_unionpay.jsp").forward(request, customResponse1);
			
			String content = customResponse1.getOutput();
			System.out.println("jsp/map/_appendix_unionpay.jsp content: \r\n"+ content);
			String subject = "Maybank UnionPay Submission";
			
			Notification n = new Notification();
			ok = n.createNotificationQueue(email, "UnionPay Submission", subject, content, oSecUserDao.getLogonId());
			if(ok == false) {
				json_error(n.getMessage(), response);
				return null;
			}
		}
		
		json_ok(response);
		return null;
	}
	
	
	public ActionForward create_appendix_partner(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.create_appendix_partner";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int case_id = Integer.parseInt(request.getParameter("case_id"));
		int merchant_id = Integer.parseInt(request.getParameter("merchant_id"));
		int outlet_id = Integer.parseInt(request.getParameter("outlet_id"));
		String partner_name = request.getParameter("partner_name");
		String email = request.getParameter("email");
		
		OutletFactory o = new OutletFactory();
		CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		JSONObject pos_form = new JSONObject();
		JSONObject appendix = new JSONObject();
		JSONObject appdx_item = new JSONObject();
		
		if(c_outlet.getPosForm().length() > 0){
			pos_form = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
			
			if(pos_form.get("appendix") != null) {
				appendix = (JSONObject) pos_form.get("appendix");
				
				if(appendix.get(partner_name) != null){
					appdx_item = (JSONObject) appendix.get(partner_name);
					appdx_item.put("last_sent", new Date().getTime());
					
					appendix.put(partner_name, appdx_item);
				}
				
				pos_form.put("appendix", appendix);
			}
		}
		
		
		
		boolean ok = o.editCaseOutletPOSForm(case_id, outlet_id, pos_form.toString());
		if(ok == false){
			json_error(o.getMessage(), response);
			return null;
		}
		
		
		
		Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
		if(m_case == null){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		
		ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
		if(c_outlets == null){
			json_error(o.getMessage(), response);
			return null;
		}
	
		
		
		c_outlet = o.getCaseOutlet(case_id, outlet_id);
		if(c_outlet == null){
			System.out.println(o.getMessage());
			return null;
		}
		
		request.setAttribute("c_outlet", c_outlet);
		
		request.setAttribute("merchant_id", merchant_id);
		request.setAttribute("case_id", case_id);
		request.setAttribute("partner_name", partner_name);
		request.setAttribute("m_case", m_case);
		request.setAttribute("c_outlets", c_outlets);
		request.setAttribute("via_email", "Y");
		
		
		CharArrayWriterResponse customResponse1 = new CharArrayWriterResponse(response);
		request.getRequestDispatcher("jsp/map/_vendor_pos.jsp").forward(request, customResponse1);
		
		String content = customResponse1.getOutput();
		System.out.println("jsp/map/_vendor_pos.jsp content: \r\n"+ content);
		String subject = "Maybank Vendor POS Form";
		String notificationType = "";
		
		if(partner_name.equals("AEON")){
			notificationType = "POS-AEON";
		} else if(partner_name.equals("DINERS")){
			notificationType = "POS-DINERS";
		} else if(partner_name.equals("GENTING")){
			notificationType = "POS-GENTING";
		} else if(partner_name.startsWith("Tag On - ")) {
			notificationType = "POS-TAGON";
		} else if(partner_name.startsWith("Vendor - ")) {
			notificationType = "POS-VENDOR";
		}
		
		Notification n = new Notification();
		ok = n.createNotificationQueue(email, notificationType, subject, content, oSecUserDao.getLogonId());
		if(ok == false) {
			json_error(n.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	
	public ActionForward visa_vmts_batch(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.visa_vmts_batch";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		String case_json_arr = request.getParameter("case_arr");
		
		boolean ok = CasemastFactory.visa_vmts_batch_submit(case_json_arr, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward best_practice(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.best_practice";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("case_id")));
		
		TreeMap<String, String> post = new TreeMap<String, String>();
		post.put("best_practice", request.getParameter("best_practice"));
		
		boolean ok = CasemastFactory.best_practice_submit(case_id, post, oSecUserDao.getLogonId());
		if(ok == false){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		json_ok(response);
		return null;
	}
	
	public ActionForward vendor_pos_3(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.vendor_pos_3";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		String serial_no = "";
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(this.authorized(request) == false){
			json_error("Unauthorized access.", response);
			return null;
		}
		
		if(request.getParameter("serial_no") != null) {
			serial_no = sanitize(request.getParameter("serial_no"));
			
		
			OutletFactory o = new OutletFactory();
			CaseOutlet c_outlet = o.getCaseOutletBySerialNo(serial_no);
			if(c_outlet == null){
				json_error("Failed to get Vendor from the serial no: " + serial_no, response);
				return null;
			}
		}
		
		JSONObject data = new JSONObject();
		data.put("serial_no", EncryptionHelper.encryptEncodeURL(serial_no));
		json_ok(response, data);
		
		return null;
	}
	
	public String buildManualContent(Casemast m_case){
		String contentHTML = "";

		JSONObject document_checklist = new JSONObject();
		JSONObject general = new JSONObject();
		JSONObject private_limited = new JSONObject();
		JSONObject sole_proprietor_partnership = new JSONObject();
		JSONObject clinic = new JSONObject();
		JSONObject jmb = new JSONObject();
		JSONObject law_firm = new JSONObject();
		JSONObject association = new JSONObject();

		String business_type = "";

		if(m_case != null) {

			if(m_case.getDocumentChecklist().length() > 0){
				document_checklist = (JSONObject) JSONValue.parse(m_case.getDocumentChecklist());
			}

			business_type = document_checklist.get("business_type") == null ? "" : document_checklist.get("business_type").toString();

			if(document_checklist.get("general") != null){
				general = (JSONObject) document_checklist.get("general");
			}

			if(document_checklist.get("private_limited") != null){
				private_limited = (JSONObject) document_checklist.get("private_limited");
			}

			if(document_checklist.get("sole_proprietor_partnership") != null){
				sole_proprietor_partnership = (JSONObject) document_checklist.get("sole_proprietor_partnership");
			}

			if(document_checklist.get("clinic") != null){
				clinic = (JSONObject) document_checklist.get("clinic");
			}

			if(document_checklist.get("jmb") != null){
				jmb = (JSONObject) document_checklist.get("jmb");
			}

			if(document_checklist.get("law_firm") != null){
				law_firm = (JSONObject) document_checklist.get("law_firm");
			}

			if(document_checklist.get("association") != null){
				association = (JSONObject) document_checklist.get("association");
			}
		}

		contentHTML = "   " +
//				"\r\n	<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">    " +
				"\r\n	<html>    " +
//				"\r\n	<head>    " +
//				"\r\n	<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">    " +
//				"\r\n	<link rel=\"stylesheet\" type=\"text/css\" href=\"/mbbmap/css/bootstrap.css\" />     " +
//				"\r\n	<link rel=\"stylesheet\" type=\"text/css\" href=\"/mbbmap/css/map.css\" />     " +
//				"\r\n	<script src=\"/mbbmap/js/jquery-1.10.2.js\"></script>    " +
//				"\r\n	<script src=\"/mbbmap/js/ui.js\"></script>   " +
//				"\r\n	<script src=\"/mbbmap/js/json2.js\"></script>   " +
//				"\r\n	<script src=\"/mbbmap/js/tab.js\"></script>     " +
//				"\r\n	<script src=\"/mbbmap/js/merchant.js\"></script>   " +
//				"\r\n	<script type=\"text/javascript\">var jq_main_url = \"/mbbmap\";</script>     " +
//				"\r\n	<title>MAYBANK</title>   " +
//				"\r\n	</head>   " +
//				"\r\n	<body>    " +
//				"\r\n	    " +
//				"\r\n	<!-- Header -->    " +
//				"\r\n	<form id=\"homePageLogo\" name=\"homePageLogo\" action=\"/mbbmap/CheckUserLogon.do?dispatch=homePage\" method=\"post\">    " +
//				"\r\n		<div id=\"bgWrapperHome\">    " +
//				"\r\n			<div class=\"headerBar\">    " +
//				"\r\n				<div class=\"headerBarBorder\">   " +
//				"\r\n					<div class=\"containerHome\">    " +
//				"\r\n						<div class=\"logo\"><a href=\"#\" onclick=\"document.getElementById('homePageLogo').submit()\"><img src=\"resource/logo-maybank.png\"></a></div>     " +
//				"\r\n						<div class=\"logdetails clearfix\">   " +
//				"\r\n						 	&nbsp;     " +
//				"\r\n						</div>	    " +
//				"\r\n					</div>    " +
//				"\r\n				</div>     " +
//				"\r\n			</div>   " +
//				"\r\n		</div>    " +
//				"\r\n	</form>	     " +
//				"\r\n	<!-- End Header -->   " +
//				"\r\n	    " +
				"\r\n	<div class=\"row-fluid page\">   " +
				"\r\n		<div class=\"span12\">     " +
				"\r\n			<form class=\"form-horizontal\" name=\"form\">   " +
				"\r\n				<table class=\"tbl general\" style=\"width:auto; margin-bottom:30px\"><thead>    " +
				"\r\n					<tr>   " +
				"\r\n						<th style=\"width:90px\">Not Required</th>     " +
				"\r\n						<th style=\"width:70px\">Available</th>     " +
				"\r\n						<th>Document Name</th>     " +
				"\r\n					</tr>     " +
				"\r\n				</thead><tbody>     " +
				"\r\n					<tr data-name=\"Approval Paper\">   ";

		String checked = "disabled ";
		String checked2 = "disabled ";
		String name = "Approval Paper";
		JSONObject item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Approval Paper</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Letter of Acceptance/Letter of Offer\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Letter of Acceptance/Letter of Offer";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Letter of Acceptance/Letter of Offer</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Merchant Application Form\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Merchant Application Form";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Merchant Application Form</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Business License\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Business License";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Business License</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Site photos (outside with signboard)\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Site photos (outside with signboard)";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Site photos (outside with signboard)</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Site photos (inside premise)\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Site photos (inside premise)";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Site photos (inside premise)</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Terminal Rental Deposit\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Terminal Rental Deposit";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Terminal Rental Deposit</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Terminal Deposit\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Terminal Deposit";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Terminal Deposit</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Advance Terminal Rental\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Advance Terminal Rental";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Advance Terminal Rental</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Amex Tag On Fee\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Amex Tag On Fee";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Amex Tag On Fee</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Financial Checking\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Financial Checking";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Financial Checking</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"MATCH/TRACE result\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "MATCH/TRACE result";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>MATCH/TRACE result</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"RMS Comments\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "RMS Comments";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>RMS Comments</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Letter of Guarantee & NRIC of Guarantors\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Letter of Guarantee & NRIC of Guarantors";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Letter of Guarantee & NRIC of Guarantors</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"3 Months Bank Statements\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "3 Months Bank Statements";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>3 Months Bank Statements</td>   " +
				"\r\n					</tr>   " +
				"\r\n					<tr data-name=\"Branch Recommendation\">   ";

		checked = "disabled ";
		checked2 = "disabled ";
		name = "Branch Recommendation";
		item = null;

		if(general.get(name) != null){
			item = (JSONObject) general.get(name);

			if(item.get("not_required").toString().equals("Y")){
				checked += "checked ";
			}

			if(item.get("available").toString().equals("Y")){
				checked2 += "checked ";
			}
		}

		contentHTML = contentHTML + 
				"\r\n						<td class=\"not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
				"\r\n						<td class=\"available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
				"\r\n						<td>Branch Recommendation</td>   " +
				"\r\n					</tr>   " +
				"\r\n				</tbody></table>   " +
				"\r\n				   " +
				"\r\n				<p><strong>" +  business_type + "</strong></p>   ";

		String comment = "";
		if(business_type.equals("For Private Limited Company")) {

			contentHTML = contentHTML + 
					"\r\n					<table class=\"tbl private_limited\" style=\"width:auto;\"><thead>   " +
					"\r\n						<tr>   " +
					"\r\n							<th colspan=\"2\">Original CTC</th>   " +
					"\r\n							<th colspan=\"2\">Not Original CTC (With Original Sighted)</th>   " +
					"\r\n							<th rowspan=\"2\">Document Name</th>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n						</tr>   " +
					"\r\n					</thead><tbody>   " +
					"\r\n						<tr data-name=\"Form 24\">   ";

			String checked_b_1 = "disabled ";
			String checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Form 24";
			item = null;

			if(private_limited.get(name) != null){
				item = (JSONObject) private_limited.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Form 24</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"Form 49\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Form 49";
			item = null;

			if(private_limited.get(name) != null){
				item = (JSONObject) private_limited.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Form 49</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"M&A\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "M&A";
			item = null;

			if(private_limited.get(name) != null){
				item = (JSONObject) private_limited.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>M&A</td>   " +
					"\r\n						</tr>   " +
					"\r\n					</tbody></table>   " +
					"\r\n					   " +
					"\r\n					<div class=\"private_limited control-group\" style=\"margin-top:10px\">   ";

			comment = "";	
			if(private_limited.get("remarks") != null) {
				comment = private_limited.get("remarks").toString();
			}

			contentHTML = contentHTML + 
					"\r\n						<p>Remarks</p>   " +
					"\r\n						<textarea disabled style=\"width:600px; height:60px\">" +  comment + "</textarea>   " +
					"\r\n					</div>   ";

		}
		if(business_type.equals("For Sole Proprietor & Partnership")) {

			contentHTML = contentHTML + 
					"\r\n					<table class=\"tbl sole_proprietor_partnership\" style=\"width:auto;\"><thead>   " +
					"\r\n						<tr>   " +
					"\r\n							<th colspan=\"2\">Original Sighted</th>   " +
					"\r\n							<th colspan=\"2\">Not Original Sighted</th>   " +
					"\r\n							<th rowspan=\"2\">Document Name</th>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n						</tr>   " +
					"\r\n					</thead><tbody>   " +
					"\r\n						<tr data-name=\"Borang D/E\">   ";

			String checked_b_1 = "disabled ";
			String checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Borang D/E";
			item = null;

			if(sole_proprietor_partnership.get(name) != null){
				item = (JSONObject) sole_proprietor_partnership.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Borang D/E</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"NRIC Copy\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "NRIC Copy";
			item = null;

			if(sole_proprietor_partnership.get(name) != null){
				item = (JSONObject) sole_proprietor_partnership.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>NRIC Copy</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"Business Registration Form (Sijil Pendaftaran)\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Business Registration Form (Sijil Pendaftaran)";
			item = null;

			if(sole_proprietor_partnership.get(name) != null){
				item = (JSONObject) sole_proprietor_partnership.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Business Registration Form (Sijil Pendaftaran)</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"Extract of Registration of Business Name (Applicable to Sarawak)\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Extract of Registration of Business Name (Applicable to Sarawak)";
			item = null;

			if(sole_proprietor_partnership.get(name) != null){
				item = (JSONObject) sole_proprietor_partnership.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Extract of Registration of Business Name (Applicable to Sarawak)</td>   " +
					"\r\n						</tr>   " +
					"\r\n					</tbody></table>   " +
					"\r\n					   " +
					"\r\n					<div class=\"sole_proprietor_partnership control-group\" style=\"margin-top:10px\">   ";

			comment = "";	
			if(sole_proprietor_partnership.get("remarks") != null) {
				comment = sole_proprietor_partnership.get("remarks").toString();
			}

			contentHTML = contentHTML + 
					"\r\n						<p>Remarks</p>   " +
					"\r\n						<textarea style=\"width:600px; height:60px\">" +  comment + "</textarea>   " +
					"\r\n					</div>   ";

		}
		if(business_type.equals("For Clinic")) {

			contentHTML = contentHTML + 
					"\r\n					<table class=\"tbl clinic\" style=\"width:auto;\"><thead>   " +
					"\r\n						<tr>   " +
					"\r\n							<th colspan=\"2\">Original Sighted</th>   " +
					"\r\n							<th colspan=\"2\">Not Original Sighted</th>   " +
					"\r\n							<th rowspan=\"2\">Document Name</th>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n						</tr>   " +
					"\r\n					</thead><tbody>   " +
					"\r\n						<tr data-name=\"Akta Kemudahan Dan Perkhidmatan Jagaan Kesihatan Swasta (Borang B/C/F)\">   ";

			String checked_b_1 = "disabled ";
			String checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Akta Kemudahan Dan Perkhidmatan Jagaan Kesihatan Swasta (Borang B/C/F)";
			item = null;

			if(clinic.get(name) != null){
				item = (JSONObject) clinic.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Akta Kemudahan Dan Perkhidmatan Jagaan Kesihatan Swasta (Borang B/C/F)</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"NRIC Copy\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "NRIC Copy";
			item = null;

			if(clinic.get(name) != null){
				item = (JSONObject) clinic.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>NRIC Copy</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"Perakuan Amalan Tahunan\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Perakuan Amalan Tahunan";
			item = null;

			if(clinic.get(name) != null){
				item = (JSONObject) clinic.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Perakuan Amalan Tahunan</td>   " +
					"\r\n						</tr>   " +
					"\r\n					</tbody></table>   " +
					"\r\n					   " +
					"\r\n					<div class=\"clinic control-group\" style=\"margin-top:10px\">   ";

			comment = "";	
			if(clinic.get("remarks") != null) {
				comment = clinic.get("remarks").toString();
			}

			contentHTML = contentHTML + 
					"\r\n						<p>Remarks</p>   " +
					"\r\n						<textarea style=\"width:600px; height:60px\">" +  comment + "</textarea>   " +
					"\r\n					</div>   ";

		}
		if(business_type.equals("For JMB")) {

			contentHTML = contentHTML + 
					"\r\n					<table class=\"tbl jmb\" style=\"width:auto;\"><thead>   " +
					"\r\n						<tr>   " +
					"\r\n							<th colspan=\"2\">Original Sighted</th>   " +
					"\r\n							<th colspan=\"2\">Not Original Sighted</th>   " +
					"\r\n							<th rowspan=\"2\">Document Name</th>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n						</tr>   " +
					"\r\n					</thead><tbody>   " +
					"\r\n						<tr data-name=\"Perakuan Penubuhan Badan Pengurusan Bersama\">   ";

			String checked_b_1 = "disabled ";
			String checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Perakuan Penubuhan Badan Pengurusan Bersama";
			item = null;

			if(jmb.get(name) != null){
				item = (JSONObject) jmb.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Perakuan Penubuhan Badan Pengurusan Bersama</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"NRIC Copy\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "NRIC Copy";
			item = null;

			if(jmb.get(name) != null){
				item = (JSONObject) jmb.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>NRIC Copy</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"Minutes of Meeting / List of Committee\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Minutes of Meeting / List of Committee";
			item = null;

			if(jmb.get(name) != null){
				item = (JSONObject) jmb.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Minutes of Meeting / List of Committee</td>   " +
					"\r\n						</tr>   " +
					"\r\n					</tbody></table>   " +
					"\r\n					   " +
					"\r\n					<div class=\"jmb control-group\" style=\"margin-top:10px\">   ";

			comment = "";	
			if(jmb.get("remarks") != null) {
				comment = jmb.get("remarks").toString();
			}

			contentHTML = contentHTML + 
					"\r\n						<p>Remarks</p>   " +
					"\r\n						<textarea style=\"width:600px; height:60px\">" +  comment + "</textarea>   " +
					"\r\n					</div>   ";

		}
		if(business_type.equals("For Law Firm")) {

			contentHTML = contentHTML + 
					"\r\n					<table class=\"tbl law_firm\" style=\"width:auto;\"><thead>   " +
					"\r\n						<tr>   " +
					"\r\n							<th colspan=\"2\">Original Sighted</th>   " +
					"\r\n							<th colspan=\"2\">Not Original Sighted</th>   " +
					"\r\n							<th rowspan=\"2\">Document Name</th>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n						</tr>   " +
					"\r\n					</thead><tbody>   " +
					"\r\n						<tr data-name=\"Akta Profession Undang-Undang\">   ";

			String checked_b_1 = "disabled ";
			String checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "Akta Profession Undang-Undang";
			item = null;

			if(law_firm.get(name) != null){
				item = (JSONObject) law_firm.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Akta Profession Undang-Undang</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"NRIC Copy\">   ";

			checked_b_1 = "disabled ";
			checked_b_2 = "disabled ";
			checked = "disabled ";
			checked2 = "disabled ";
			name = "NRIC Copy";
			item = null;

			if(law_firm.get(name) != null){
				item = (JSONObject) law_firm.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}

				if(item.get("not_required_2").toString().equals("Y")){
					checked_b_1 += "checked ";
				}

				if(item.get("available_2").toString().equals("Y")){
					checked_b_2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_1 + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"b available\"><input class=\"checkbox\" type=\"checkbox\" " + checked_b_2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>NRIC Copy</td>   " +
					"\r\n						</tr>   " +
					"\r\n					</tbody></table>   " +
					"\r\n					   " +
					"\r\n					<div class=\"law_firm control-group\" style=\"margin-top:10px\">   ";

			comment = "";	
			if(law_firm.get("remarks") != null) {
				comment = law_firm.get("remarks").toString();
			}

			contentHTML = contentHTML + 
					"\r\n						<p>Remarks</p>   " +
					"\r\n						<textarea style=\"width:600px; height:60px\">" +  comment + "</textarea>   " +
					"\r\n					</div>   ";

		}
		if(business_type.equals("For Association, Charity Body, etc")) {

			contentHTML = contentHTML + 
					"\r\n					<table class=\"tbl association\" style=\"width:auto;\"><thead>   " +
					"\r\n						<tr>   " +
					"\r\n							<th style=\"width:90px\">Not Required</th>   " +
					"\r\n							<th style=\"width:70px\">Available</th>   " +
					"\r\n							<th>Document Name</th>   " +
					"\r\n						</tr>   " +
					"\r\n					</thead><tbody>   " +
					"\r\n						<tr data-name=\"Letter of Registration\">   ";

			checked = "disabled ";
			checked2 = "disabled ";
			name = "Letter of Registration";
			item = null;

			if(association.get(name) != null){
				item = (JSONObject) association.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Letter of Registration</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"NRIC copy of Authorised Signatories\">   ";

			checked = "disabled ";
			checked2 = "disabled ";
			name = "NRIC copy of Authorised Signatories";
			item = null;

			if(association.get(name) != null){
				item = (JSONObject) association.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>NRIC copy of Authorised Signatories</td>   " +
					"\r\n						</tr>   " +
					"\r\n						<tr data-name=\"Minutes of Meeting / List of Committee\">   ";

			checked = "disabled ";
			checked2 = "disabled ";
			name = "Minutes of Meeting / List of Committee";
			item = null;

			if(association.get(name) != null){
				item = (JSONObject) association.get(name);

				if(item.get("not_required_1").toString().equals("Y")){
					checked += "checked ";
				}

				if(item.get("available_1").toString().equals("Y")){
					checked2 += "checked ";
				}
			}

			contentHTML = contentHTML + 
					"\r\n							<td class=\"a not_required\"><input class=\"checkbox\" type=\"checkbox\" " + checked + " value=\"Y\" /></td>   " +
					"\r\n							<td class=\"a available\"><input class=\"checkbox\" type=\"checkbox\" " + checked2 + " value=\"Y\" /></td>   " +
					"\r\n							<td>Minutes of Meeting / List of Committee</td>   " +
					"\r\n						</tr>   " +
					"\r\n					</tbody></table>   " +
					"\r\n					   " +
					"\r\n					<div class=\"association control-group\" style=\"margin-top:10px\">   ";

			comment = "";	
			if(association.get("remarks") != null) {
				comment = association.get("remarks").toString();
			}

			contentHTML = contentHTML + 
					"\r\n						<p>Remarks</p>   " +
					"\r\n						<textarea style=\"width:600px; height:60px\">" +  comment + "</textarea>   " +
					"\r\n					</div>   ";

		}

		contentHTML = contentHTML + 
				"\r\n			</form>   " +
				"\r\n			   " +
				"\r\n		</div>   " +
				"\r\n	</div>   " +
				"\r\n	   " +
//				"\r\n	</body>   " +
				"\r\n	</html>   ";

		return contentHTML;
	}
}